package main

import (
	"context"
	"fmt"
	"grpc-1/pb/services"

	"log"

	"google.golang.org/grpc"
)

//需要拷贝根据 Prod.proto 生成的两个文件( Prod.pb.go Prod_grpc.pb.go )
func main() {
	//连接服务端
	//为避免缺少证书 no transport security set (use grpc.WithInsecure() explicitly or set credentials)
	conn, err := grpc.Dial(":8081", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("连接GRPC服务端失败 %v\n", err)
	}

	defer conn.Close()
	prodClient := services.NewProductServiceClient(conn)
	prodRes, err := prodClient.GetProductStock(
		//先随意传递上下文
		context.Background(),
		//业务入参
		&services.ProdRequest{ProdId: 12},
	)

	if err != nil {
		log.Fatalf("请求GRPC服务端失败 %v\n", err)
	}
	fmt.Println(prodRes.ProdStock)
}
